﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using BuyLocalBonds;

namespace TestBuyLocalBonds
{
    /// <summary>
    /// More Test-cases:
    /// 1. If quantity available doesn't match the database value
    /// </summary>
    [TestFixture]
    public class TestBuyBond
    {
        #region Private Variables

        private string cusip;
        private int qty;
        private string custID;
        private string traderID;
        private int qtyAvail;

        private SqlBean sqlBean;

        #endregion Private Variables

        [SetUp]
        public void SetUp()
        {
            // All Legal values
            cusip = "000000002";
            custID = "103";
            traderID = "104";
            qty = 5;
            qtyAvail = 25;

            // set qtyAvail for the above cusip to 25 in the database

            sqlBean = new SqlBean();
        }

        [TearDown]
        public void TearDown()
        {
            // reset qtyAvail to original value to 25 in the database
        }

        #region CUSIP

        [Test]
        public void NullCusip()
        {
            cusip = null;
            bool status = sqlBean.BuyBond(cusip, qty, custID, traderID, qtyAvail);

            Assert.IsFalse(status, "Null Cusip provided");
        }

        [Test]
        public void EmptyCusip()
        {
            cusip = "";
            bool status = sqlBean.BuyBond(cusip, qty, custID, traderID, qtyAvail);

            Assert.IsFalse(status, "Empty Cusip provided");
        }

        #endregion CUSIP

        #region Quantity

        [Test]
        public void NegativeQty()
        {
            qty = -5;
            bool status = sqlBean.BuyBond(cusip, qty, custID, traderID, qtyAvail);

            Assert.IsFalse(status, "Negative Quantity provided");
        }

        [Test]
        public void ZeroQty()
        {
            qty = 0;
            bool status = sqlBean.BuyBond(cusip, qty, custID, traderID, qtyAvail);

            Assert.IsFalse(status, "Zero Quantity provided");
        }

        [Test]
        public void PositiveInfiniteQty()
        {
            qty = Int32.MaxValue;
            bool status = sqlBean.BuyBond(cusip, qty, custID, traderID, qtyAvail);

            Assert.IsFalse(status, "Positive Infinite Quantity provided");
        }

        [Test]
        public void NegativeInfiniteQty()
        {
            qty = Int32.MinValue;
            bool status = sqlBean.BuyBond(cusip, qty, custID, traderID, qtyAvail);

            Assert.IsFalse(status, "Negative Infinite Quantity provided");
        }

        #endregion Quantity

        #region CustomerID

        [Test]
        public void EmptyCustID()
        {
            custID = "";
            bool status = sqlBean.BuyBond(cusip, qty, custID, traderID, qtyAvail);

            Assert.IsFalse(status, "Empty CustomerID provided");
        }

        [Test]
        public void NullCustID()
        {
            custID = null;
            bool status = sqlBean.BuyBond(cusip, qty, custID, traderID, qtyAvail);

            Assert.IsFalse(status, "Null CustomerID provided");
        }

        #endregion CustomerID

        #region TraderID

        [Test]
        public void EmptyTraderID()
        {
            traderID = "";
            bool status = sqlBean.BuyBond(cusip, qty, custID, traderID, qtyAvail);

            Assert.IsFalse(status, "Empty TraderID provided");
        }

        [Test]
        public void NullTraderID()
        {
            traderID = null;
            bool status = sqlBean.BuyBond(cusip, qty, custID, traderID, qtyAvail);

            Assert.IsFalse(status, "Null TraderID provided");
        }

        #endregion TraderID

        #region Use-Cases

        /// <summary>
        /// Supply a CUSIP that doesn't exist in the database
        /// </summary>
        [Test]
        public void BuyBondThatDoesntExist()
        {
            cusip = "123456789";
            bool status = sqlBean.BuyBond(cusip, qty, custID, traderID, qtyAvail);

            Assert.IsFalse(status, "Bond with the supplied CUSIP doesn't exist in the database");
        }

        [Test]
        public void BuyMoreThanAvailableQuantity()
        {
            qty = 30;
            bool status = sqlBean.BuyBond(cusip, qty, custID, traderID, qtyAvail);

            Assert.IsFalse(status, "The requested quantity is not available");
        }

        [Test]
        public void InvalidCustomer()
        {
            custID = "123456789";
            bool status = sqlBean.BuyBond(cusip, qty, custID, traderID, qtyAvail);

            Assert.IsFalse(status, "The customerID doesn't exist in the database");
        }

        [Test]
        public void InvalidTrader()
        {
            traderID = "123456789";
            bool status = sqlBean.BuyBond(cusip, qty, custID, traderID, qtyAvail);

            Assert.IsFalse(status, "The traderID doesn't exist in the database");
        }

        #endregion Use-Cases
    }
}
